# coding=utf-8
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class MainWindow(QMainWindow):
    count=0
    def __init__(self,parent=None):
        super(MainWindow, self).__init__()
        self.mdi=QMdiArea()
        self.setCentralWidget(self.mdi)
        bar=self.menuBar()
        file=bar.addMenu('文件')
        file.addAction('新建')
        file.addAction('层级显示')
        file.addAction('平铺显示')
        file.triggered[QAction].connect(self.windowaction)
        self.setWindowTitle('MDI demo')

    def windowaction(self,q):
        if q.text()=='新建':
            MainWindow.count=MainWindow.count+1
            sub=QMdiSubWindow()
            sub.setWidget(QTextEdit())
            sub.setWindowTitle('子窗体'+str(MainWindow.count))
            self.mdi.addSubWindow(sub)
            sub.show()
        if q.text()=='层级显示':
            self.mdi.cascadeSubWindows()
        if q.text()=='平铺显示':
            self.mdi.tileSubWindows()

if __name__=='__main__':
    app=QApplication(sys.argv)
    demo=MainWindow()
    demo.show()
    sys.exit(app.exec_())
